package com.hksj.data.event.listener;

import com.hksj.data.event.*;
import com.hksj.data.thing.RawData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author zengke
 * @version 1.0
 * @see WriteDataEventListener
 * @since 2025/08/15 10:13
 */

@Component
public class WriteDataEventListener {

    @Autowired
    private ApplicationEventPublisher publisher;

    /**
     * 监听写入数据的事件
     * @param event 写入数据事件
     */
    @Async
    @EventListener
    public void onWriteDataEvent(WriteDataEvent event){

        //获取原始数据
        RawData data = event.getData();


        //发布存储mysql的原始数据存储的消息
        publisher.publishEvent(new WriteRawMysqlDataEvent(data));

        //发布存储mysql的解析数据存储的消息
        publisher.publishEvent(new WriteParseMysqlDataEvent(data));

        //发布tdengine原始数据存储的消息
        publisher.publishEvent(new WriteRawTdengineDataEvent(data));

        //发布tdengine解析数据存储的消息
        publisher.publishEvent(new WriteParseTdengineDataEvent(data));

    }
}
